package arduinoInterface_test;

import static org.junit.Assert.*;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class SerialCommunicationTest_Reader {

	String portNumber="COM5";
	int boudRate=9600;
	ByteArrayOutputStream out=new ByteArrayOutputStream();
	SerialCommunication serial;
	
	
	@Before
    public void setUp() {
		serial= new SerialCommunication(boudRate,portNumber,out);
    }

	
	
	@After
    public void tearDown() throws IOException {
       
		serial.closePort();
		
		
    }


	@Test
	public void testGetTemperaturaFromSerialReader() throws InterruptedException {
		
		
		Thread.sleep(1000);
		
		//System.out.println(serial.getTemperaturaFromSerialReader()+"prova");
		
		assertEquals(20,serial.getTemperaturaFromSerialReader(),10);
		
	}
	@Test
	public void testGetLuminositaFromSerialReader() throws InterruptedException {
		
		Thread.sleep(1000);
		
		System.out.println(serial.getluminositaFromSerialReader()+"prova");
		
		assertEquals(600,serial.getluminositaFromSerialReader(),50);
		
		
		
	}

	@Test
	public void testGetPirFromSerialReader() throws InterruptedException {

		Thread.sleep(1000);
		
		System.out.println(serial.getPirFromSerialReader()+"prova");
		
		
		//Per il file di esempio abbiamo impostato pir = false
		assertEquals("false",serial.getPirFromSerialReader());
		
	}

	@Test
	public void testGetLedFromSerialReader() throws InterruptedException {
		
		Thread.sleep(1000);
		
		System.out.println(serial.getLedFromSerialReader()+"prova");
		
		
		//Per il file di esempio abbiamo impostato led = false
		assertEquals("false",serial.getLedFromSerialReader());
		
		
	}

	@Test
	public void testGetStatoLettura() {
		
		serial.setStatoLettura(true);
		assertTrue(serial.getStatoLettura());
		
		serial.setStatoLettura(false);
		assertFalse(serial.getStatoLettura());
		
		
	}

	
	@Test
	public void testSetStatoLettura() {
		
		
		//Si puo' testare uglualmente alla get
		
		serial.setStatoLettura(true);
		assertTrue(serial.getStatoLettura());
		
		serial.setStatoLettura(false);
		assertFalse(serial.getStatoLettura());
		
		
	}
	
	

}
